local jingyi = fk.CreateSkill{
  name = "xiaobai__jingyi",
  tags = {
    Skill.Compulsory
  }
}

Fk:loadTranslationTable{
  ["xiaobai__jingyi"] = "境颐",
  [":xiaobai__jingyi"] = "锁定技，一名角色的回合结束时，若本回合没有角色受到过伤害或有角色失去过最后一张手牌，你摸一张牌。"..
    "若均满足：重置“诚谟”，当前回合角色也摸一张牌。",
  ["@xiaobai__jingyi-turn"] = "境颐",
  ["xiaobai__jingyi_damage"] = "伤害",
  ["xiaobai__jingyi_lose"] = "失去"
}

jingyi:addEffect(fk.TurnEnd, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(jingyi.name) and (#player:getTableMark("@xiaobai__jingyi-turn") > 0)
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:drawCards(player, 1, jingyi.name)
    if #player:getTableMark("@xiaobai__jingyi-turn") == 2 then
      player:setSkillUseHistory("xiaobai__chengmo")
      room:drawCards(room.current, 1, jingyi.name)
    end
  end
})

jingyi:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(jingyi.name)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addTableMark(player, "@xiaobai__jingyi-turn", "xiaobai__jingyi_damage")
  end
})

jingyi:addEffect(fk.DamageFinished, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(jingyi.name)
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:removeTableMark(player, "@xiaobai__jingyi-turn", "xiaobai__jingyi_damage")
  end
})

jingyi:addAcquireEffect(function (self, player, is_start)
  if not is_start then
    if #player.room.logic:getActualDamageEvents(1, Util.TrueFunc, Player.HistoryTurn) == 0 then
      player.room:addTableMark(player, "@xiaobai__jingyi-turn", "xiaobai__jingyi_damage")
    end
  end
end)

jingyi:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    if not (player:hasSkill(jingyi.name)) then return end
    for _, move in ipairs(data) do
      if move.from and move.from:isKongcheng() then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand  then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addTableMark(player, "@xiaobai__jingyi-turn", "xiaobai__jingyi_lose")
  end
})

return jingyi